<div class="content-wrapper">
	<section class="content-header">
		<h1>用户组列表</h1>
		<ol class="breadcrumb">
			<li><a href="/admin"><i class="fa fa-dashboard"></i> 首页</a></li>
			<li class="active">权限管理</li>
			<li class="active">用户组列表</li>
		</ol>
	</section>
	<section class="content">
		<div class="box">
			<div class="box-header with-border">
				<form class="form-inline">
					<input type="hidden" name="id" id="id" value="{$groupInfo.id}" />
					<div class="form-group">
						<label for="name">用户组名 </label> 
						<input type="text" class="form-control" id="name" name="name" placeholder="用户组名" value="{$groupInfo.name}">
					</div>
					<div class="form-group">
						<label for="name">录入数量 </label>
						<input type="text" class="form-control" id="total_enrollment" name="total_enrollment" placeholder="人" value="{$groupInfo.total_enrollment}">
					</div>
					<div class="form-group">
						<label for="name">更新间隔 </label>
						<input type="text" class="form-control" id="tracking_time" name="tracking_time" placeholder="天" value="{$groupInfo.tracking_time}">
					</div>
					<button type="button" class="btn btn-info" id="save-btn">{$groupInfo?'修改':'添加'}</button>&nbsp;
					<button type="button" class="btn btn-danger" onclick="window.location.href='/admin/auth/userGroupList'">取消</button>
				</form>
			</div>
			<div class="box-body">
				<table class="table table-bordered">
					<tbody>
						<tr>
							<th style="width: 40px">ID</th>
							<th>用户组名</th>
							<th>录入数量</th>
							<th>更新间隔</th>
							<th>成员数</th>
							<th style="width: 215px">操作</th>
						</tr>
						<foreach name="groupList" item="group">
                        	<tr>
                        		<td>{$group.id}</td>
                        		<td>{$group.name}</td>
                        		<td>{$group.total_enrollment}</td>
                        		<td>{$group.tracking_time}</td>
                        		<td>{$group.user_num}</td>
                        		<td>
                        			<button class="btn btn-info btn-xs" type="button" onclick="window.location.href='/admin/auth/setUserGroupFunction?user_group_id={$group.id}'">设置小组权限</button>&nbsp;
                        			<button class="btn btn-danger btn-xs" type="button" onclick="window.location.href='/admin/auth/userGroupList?id={$group.id}'">修改</button>&nbsp;
                        			<button class="btn btn-primary btn-xs" type="button" onclick="window.location.href='/admin/user/userList?user_group_id={$group.id}'">成员</button>&nbsp;
                        		</td>
                        	</tr>
                        </foreach>
					</tbody>
				</table>
			</div>			
		</div>
	</section>
</div>

<script type="text/javascript">
$(function(){
	$("#save-btn").click(function(){
		var id = $("#id").val();
		var name = $.trim($("#name").val());
		var total_enrollment = $.trim($("#total_enrollment").val());
		var tracking_time = $.trim($("#tracking_time").val());

		if(name == '') {
			ArtDialogHlp.showInfo('提示', '请填写用户组名');
            return false;
        }
        if(total_enrollment == '' || isNaN(total_enrollment)) {
            ArtDialogHlp.showInfo('提示', '请填写正确的录入数量');
            return false;
        }
        if(tracking_time == '' || isNaN(tracking_time)) {
            ArtDialogHlp.showInfo('提示', '请填写正确的更新间隔');
            return false;
        }
		
		$.post('/admin/auth/saveUserGroup', {
		    id:id,
			name:name,
            tracking_time: tracking_time,
            total_enrollment: total_enrollment
		}, function(data){
			if(data.Code == 999) {
				ArtDialogHlp.showInfo('提示', '操作成功', function(){
					window.location.href = '/admin/auth/userGroupList';
				});
			} else {
				ArtDialogHlp.showInfo('提示', data.Msg);
			}
		}, 'json');
	});
});
</script>